import 'dart:io';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class GTSUtils {
  static FToast fToast = FToast();
  static CancelFunc? lastCancelFunc;
  static void showToast(String message, {BuildContext? context}) {
    if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) {
      Fluttertoast.showToast(
          msg: message,
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.CENTER,
          timeInSecForIosWeb: 1,
          backgroundColor: Colors.greenAccent,
          textColor: Colors.black,
          fontSize: 16.0);
    } else {
      Widget toast = Center(
          child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(25.0),
          color: Colors.greenAccent,
        ),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            const Icon(Icons.info_outline),
            const SizedBox(
              width: 12.0,
            ),
            Text(
              message,
              style: const TextStyle(
                  fontSize: 18,
                  color: Colors.black,
                  fontStyle: FontStyle.normal,
                  fontWeight: FontWeight.normal,
                  decoration: TextDecoration.none),
            ),
          ],
        ),
      ));
      lastCancelFunc?.call();
      lastCancelFunc = BotToast.showWidget(toastBuilder: (cancelFunc) {
        Future.delayed(const Duration(seconds: 2), cancelFunc);
        return toast;
      });
    }
  }
}
